﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TAC
{
	class Dice
	{
		/*--------------------------------------------------------------------------------------------------------*/
		/*:::[FIELDS]:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
		/*--------------------------------------------------------------------------------------------------------*/

		public bool critic, miss;
		private static Random random;

		/*--------------------------------------------------------------------------------------------------------*/
		/*:::[CONSTRUCTORS]:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
		/*--------------------------------------------------------------------------------------------------------*/

		public Dice()
		{
			critic = miss = false;
			random = new Random();
		}

		/*--------------------------------------------------------------------------------------------------------*/
		/*:::[ROLLS]::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
		/*--------------------------------------------------------------------------------------------------------*/

		public int roll()
		{
			critic = miss = false;
			int result = random.Next(1, 13);
			if (result == 12)
				critic = true;
			else if (result == 1)
				miss = true;
			return result;
		}

		public int roll(int sides, int times)
		{
			if (critic)
			{
				critic = false;
				return sides * times;
			}
			else if (miss)
			{
				miss = false;
				return sides;
			}
			int result = 0;
			for (int t = 0; t < times; ++t)
				result += random.Next(1, sides+1);
			return result;
		}
	}
}
